package com.ruoyi.web.controller.system;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;

public class test {
    public static void main(String[] args) {
        jpg2png("","");
    }
    /**
     * jpg to png
     * @param jpgPath 需要被转换的jpg全路径带文件名
     * @param pngPath 转换之后png的全路径带文件名
     */
    public static void jpg2png(String jpgPath, String pngPath) {
        try {
            BufferedImage jpg = ImageIO.read(new File(jpgPath));
            BufferedImage png =new BufferedImage(jpg.getWidth(), jpg.getHeight(), BufferedImage.TYPE_INT_RGB);
            png.createGraphics().drawImage(jpg,0,0, Color.white,null);
            ImageIO.write(png, "png", new File(pngPath));
        } catch (Exception e) {
            e.printStackTrace();

        }
    }
}

